package br.org.credfaz.sis.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import br.org.credfaz.sis.MysqlConnectionFactory;
import br.org.credfaz.sis.modelo.Cliente;



public class ClienteDAO {
	
private final Connection connection;
	
	public ClienteDAO(){
		try{
			connection = new MysqlConnectionFactory().getConnection();
		}catch (SQLException e){
			throw new RuntimeException(e);
		}
	}
	
	public void adiciona(Cliente cliente){
		String sql = "insert into cliente (idcliente, numcpfcnpj, nomereceita) values (?, ?, ?)";
		PreparedStatement stmt;
		try{
			stmt = connection.prepareStatement(sql);
			
			stmt.setLong(1, cliente.getIdcliente());
			stmt.setString(2, cliente.getNumcpfcnpj());
			stmt.setString(3, cliente.getNomereceita());
			
			stmt.execute();
			
		}catch (SQLException e){
			throw new RuntimeException(e);
		}
	}
}
